package com.fxu.role.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fxu.framework.core.base.Cascade;
import com.fxu.framework.core.enums.EnumValid;
import com.fxu.framework.core.enums.StatusEnum;
import com.fxu.framework.core.sql.SEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

import static com.baomidou.mybatisplus.annotation.FieldFill.UPDATE;

/***
 * <p>测试</p>
 * 菜单表：[menu]的数据实体类
 * @author fxu
 * @version 2021-03-23
 ***/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "Menu", description = "菜单")
@TableName("fxu_menu")
public class Menu extends SEntity<Menu> implements Serializable {
/*=== 自动生成代码 开始 ===*/
    private static final long serialVersionUID = -752639756475898756L;

    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "自增ID")
    private Long id;

    @ApiModelProperty(value = "父菜单ID")
    private Long parentId;

    @ApiModelProperty(value = "菜单名", required = true)
    @NotBlank(message = "菜单名必须赋值")
    @Size(max = 32, message = "菜单名的长度必须小于32位")
    private String name;

    @ApiModelProperty(value = "图标", required = true)
//    @NotBlank(message = "图标必须赋值")
    @Size(max = 32, message = "图标的长度必须小于32位")
    private String icon;

    @ApiModelProperty(value = "地址", required = true)
//    @NotBlank(message = "地址必须赋值")
    @Size(max = 128, message = "地址的长度必须小于128位")
    private String url;

    @ApiModelProperty(value = "路由名", required = true)
    @NotBlank(message = "路由名必须赋值")
    @Size(max = 32, message = "路由名的长度必须小于32位")
    private String router;

    @ApiModelProperty(value = "vue文件", required = true)
    @NotBlank(message = "vue文件必须赋值")
    @Size(max = 64, message = "vue文件的长度必须小于64位")
    private String compt;

    @ApiModelProperty(value = "是否隐藏", required = true)
    @NotNull(message = "是否隐藏必须赋值")
    private Boolean hide;

    @ApiModelProperty(value = "权限列表")
    @Size(max = 1024, message = "权限列表的长度必须小于1024位")
    private String perms;

    @ApiModelProperty(value = "排序值")
    private Float orderNo;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    private Date updateTime;

    @ApiModelProperty(value = "状态[1:正常,0:删除]")
    @EnumValid(target = StatusEnum.class, message = "状态的值必须为{1:正常,0:删除}")
    private Integer status;

    @TableField(fill = UPDATE, update = "%s+1")
    @ApiModelProperty(value = "版本号")
    private Integer version;

    @TableField(exist = false)
    @ApiModelProperty(value = "子列表")
    @Cascade(thisField = "id", linkField = "parentId")
    private List<Menu> childList;

    /**
     * 获得状态的说明
     * @return 状态说明
     */
    public String getStatusText() {
        return StatusEnum.desc(status);
    }
/*=== 自动生成代码 结束 ===*/
}
